import { sys } from 'cc';
export class RandomTools {
    /**
     * 随机数（浮点型）
     * @param min 最小值
     * @param max 最大值
     */
    public static Random(min: number, max: number): number {
        return Math.random() * (max - min) + min;
    }
    /**
     * 随机数（整型）
     * @param min 最小值
     * @param max 最大值
     */
    public static RandomInt(min: number, max: number): number {
        return Math.floor(Math.random() * (max - min + 1) + min);
    }

    /**
    * 随机生成一个用不重复的ID
    * @param length 随机数长度
    * @returns id
    */
    public static GetUnionId(length: number, param: string = null): string {
        let union_id = RandomTools.RandomInt(10000, 99999).toString(16) + (Number(Math.random().toString().substring(3, length + 5))).toString(36);
        if (param != null) union_id = param + union_id;
        return union_id
    }

    /**
     * 生成一个用不重复的ID(带渠道)
     * @param length 随机数长度
     * @returns id
     */
    public static GetChannelUnionId(): string {
        let prev = "";
        switch (sys.platform) {
            case sys.Platform.WECHAT_GAME:
                prev = "wx";
                break;
            case sys.Platform.BYTEDANCE_MINI_GAME:
                prev = "tt";
                break;
            default:
                prev = "web";
                break;
        }
        let union_id = (Date.now() - 1724000000).toString(36);
        return prev + union_id
    }
}


